import { setToken, getToken, delToken } from "@/utils/storage";

const user = {
  namespaced: true,
  state: {
    // 刷新实现数据持久花getToken()调用一下token
    token: getToken(),
  },
  mutations: {
    setToken(state, newToken) {
      // 传过来的token存到本地
      setToken(newToken);

      // 数据给到state
      state.token = newToken;
      console.log(state.token);
    },
    delToken(state) {
      // 清空本地token
      delToken();
      // 清空vuex里的token
      state.token = null;
    },
  },
};
export default user;
